
function http(){
    this.init()
}
http.prototype.init =function(){
    //http request 拦截器
    axios.interceptors.request.use(
        config => {
            config.data = JSON.stringify(config.data);
            config.headers = {
                'Content-Type':'application/JSON'
            };
            return config;
        },
        error => {
            return Promise.reject(err);
        }
    );
}
/** 
 * @param url
 * @param data
 * @param bool
 */
http.prototype.get = function(url,data,bool){
    var b = bool || false
    return new Promise( (resolve,reject) =>{
        axios.get(url,{params:data})
        .then( resp =>{
            resolve(resp.data)
        })
        .catch( err =>{
            reject(err)
        })
        .finally( ()=>{

        })
    })
    
}
/** 
 * @param url
 * @param data
 * @param bool
 */
http.prototype.post= function(url,data,bool){
    var b = bool || false
    return new Promise((resolve,reject) => {
        axios.post(url,data)
        .then(response => {
            resolve(response.data);
        },err => {
            reject(err)
        })
        .finally( ()=>{

        });
    })
}

if(typeof define === 'function' && define.amd){
    define(function(){return http})
}else if(typeof exports === 'object'){
    if(module !== undefined && module.exports){
        exports = module.exports = http
    }
}else{
    window.$http = new http()
}